package com.foodchain.util;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;

@Slf4j
public class ReflectUtil {

    private ReflectUtil() {}

    @SneakyThrows(Exception.class)
    public static Object getField(String clazzName, String fieldName) {
        Class<?> clazz = getClass(clazzName);
        if (null == clazz) return null;
        Field filed = clazz.getDeclaredField(fieldName);
        filed.setAccessible(true);
        return filed.get(clazz);
    }

    /**
     * 根据类名称获取Class对象;
     * @param clazzName -类完全名称;
     */
    @SneakyThrows(ClassNotFoundException.class)
    public static Class<?> getClass(String clazzName) {
        return Class.forName(clazzName);
    }

}
